#ifndef __CONDITION_H_
#define __CONDITION_H_

#include "Mutex.h"
#include <pthread.h>

class Condition
{
	explicit Condition(MutexLock& lock) : _lock(lock)
	{
		pthread_cond_init(&_pcond, NULL);
	}
		
	~Condition()
  {
    pthread_cond_destroy(&_pcond);
  }

  void Wait()
  {
    pthread_cond_wait(&_pcond, _lock.GetMutex());
  }

  void Signal()
  {
    pthread_cond_signal(&_pcond);
  }

  void Broadcast()
  {
    pthread_cond_broadcast(&_pcond);
  }
		
private:
  MutexLock& _lock;
  pthread_cond_t _pcond;
};


#endif